package com.apchernykh.types;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import android.os.Parcel;
import android.os.Parcelable;

public class Show implements Parcelable {

	final private static SimpleDateFormat mCzechDateFormat = new SimpleDateFormat(
			"d MMM HH:mm", Locale.getDefault());
	private String mTitle = "Nezjisteno";
	private String mDescription = "Nezjisteno";
	private String mURL = null;
	private Date mDate = new Date();

	@Override
	public void writeToParcel(Parcel oParcel, int iUnusedFlags) {
		oParcel.writeString(mTitle);
		oParcel.writeString(mDescription);
		oParcel.writeString(mURL);
		oParcel.writeLong(mDate.getTime());
	}

	public Show() {
	}

	public Show(Parcel iParcel) {
		mTitle = iParcel.readString();
		mDescription = iParcel.readString();
		mURL = iParcel.readString();
		mDate.setTime(iParcel.readLong());
	}

	public static final Parcelable.Creator<Show> CREATOR = new Parcelable.Creator<Show>() {
		public Show createFromParcel(Parcel iParcel) {
			return new Show(iParcel);
		}

		public Show[] newArray(int iSize) {
			return new Show[iSize];
		}
	};

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}


	public String getTitle() {
		return mTitle;
	}

	public void setTitle(String iTitle) {
		if (iTitle != null)
			this.mTitle = iTitle.trim();
	}

	public String getDescription() {
		return mDescription;
	}

	public void setDescription(String iDescription) {
		if (iDescription != null)
			this.mDescription = iDescription.trim();
	}

	public String getUrl() {
		return mURL;
	}

	public void setUrl(String iUrl) {
		if (iUrl != null) {
			this.mURL = iUrl.trim();
		}
	}

	public Date getDate() {
		return mDate;
	}

	public void setDate(Date iDate) {
		if (iDate != null) {
			this.mDate = iDate;
		}
	}

	@Override
	public String toString() {
		StringBuilder aStringBuilder = new StringBuilder();
		aStringBuilder.append("Show(");
		aStringBuilder.append("mTitle='");
		aStringBuilder.append(mTitle);
		aStringBuilder.append("',mDescription='");
		aStringBuilder.append(mDescription);
		aStringBuilder.append("',mURL='");
		aStringBuilder.append(mURL);
		aStringBuilder.append("')");
		return aStringBuilder.toString();
	}

	public String getTimeString() {
		if (mDate != null)
			return mCzechDateFormat.format(mDate);
		return "??.?? ??:??"; // ???
	}
}
